package com.mz.demo.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.demo.entity.SysRole;
import com.mz.demo.entity.vo.RoleQuery;
import com.mz.demo.entity.vo.RoleVo;
import com.mz.demo.service.RoleService;
import com.mz.demo.utils.entity.PaginationVo;
import com.mz.demo.utils.entity.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 1、增加角色
     * */
    @PostMapping
    public R addRole(@RequestBody RoleVo roleVo){

        roleService.addRole(roleVo);
        return R.ok();
    }


    /**
     * 2、查询角色分页列表
     * */
    @GetMapping("/pagination")
    public R getRolePagination(PaginationVo paginationVo, RoleQuery roleQuery){

        IPage page =  roleService.getRolePagination( paginationVo, roleQuery);
        return R.ok( paginationVo, page );
    }


    /**
     * 3、获取所有角色列表
     * */
    @GetMapping("/list")
    public R getRolelist( RoleQuery roleQuery ){

        List<SysRole> roleList = roleService.getRolelist(roleQuery);
        return R.ok( roleList );
    }


    /**
     * 4、修改角色
     * */
    @PutMapping("")
    public R updateRoleInfo( @RequestBody RoleVo roleVo ){

        roleService.updateRoleInfo( roleVo );
        return R.ok();
    }


    /**
     * 5、删除角色
     * */
    @DeleteMapping("")
    public R removeRoleById( Long roleId ){

        roleService.removeRoleById(roleId);
        return R.ok();
    }


    /**
     * 6、获取角色下的权限列表
     * **/
    public R getRolePermissionList( Long roleId ){

        return R.ok();
    }
}
